package it.antonio.ilpizze.assertion.concrete;

import it.antonio.ilpizze.assertion.Assertion;
import it.antonio.ilpizze.assertion.Condition;

import java.util.Map;

public class MapAssertion extends Assertion<Map<?,?>> {

        public MapAssertion(Map<?,?> instance){
                super(instance);
        }
        
        @Override
        public MapAssertion as(String description) {
                description(description);
                return this;
        }

        @Override
        public MapAssertion doesNotSatisfy(Condition condition) {
                assertNotSatisfy(condition);
                return this;
        }

        @Override
        public MapAssertion isEqualTo(Map<?,?> expected) {
                assertEqual(expected);
                return null;
        }

        @Override
        public MapAssertion isNotEqualTo(Map<?,?> other) {
                assertNotEqual(other);
                return null;
        }

        @Override
        public MapAssertion isNotNull() {
                assertNotNull();
                return null;
        }

        @Override
        public MapAssertion isNotSameAs(Map<?,?> other) {
                assertIsNotSameAs(other);
                return null;
        }

        @Override
        public MapAssertion isSameAs(Map<?,?> expected) {
                assertIsSameAs(expected);
                return null;
        }

        @Override
        public MapAssertion satisfies(Condition condition) {
                assertSatisfy(condition);
                return null;
        }
        
        public MapAssertion hasSize(int size){
                if(instance.size() == size) return this;
                fail("the size is not " + size);
                return this;
        } 
        
        public MapAssertion isEmpty(){
                if(instance.isEmpty()) return this;
                fail("is not empty");
                return this;
        } 
        
        public MapAssertion isNotEmpty(){
                if(!instance.isEmpty()) return this;
                fail("is empty");
                return this;
        } 
        
        public MapAssertion containsKey(Object obj){
        	assertNotNull();
            if(instance.containsKey(obj)) return this;
            fail("the map does not contains key " + obj);
            return this;
        }
        
        public MapAssertion containsValue(Object obj){
        	assertNotNull();
        	if(instance.containsValue(obj)) return this;
            fail("the map does not contains value " + obj);
            return this;
        }
        
        public MapAssertion containsEntry(Object key, Object value){
        	containsKey(key);
        	return containsValue(value);
        }
}